
package cz.cvut.fel.y36mm1.videostreaming;

import cz.cvut.fel.y36mm1.videostreaming.screens.ErrorScreen;
import javax.microedition.lcdui.Displayable;

/**
 * Handles error screens. Singleton.
 * @author Jiri Chadima, chadij1
 */
public class ErrorHandler {
	private static ErrorHandler instance = null;
	private MainMidlet root;

	public void setRoot(MainMidlet root) {
		this.root = root;
	}

	/**
	 * Returns instance
	 * @return
	 */
	public static ErrorHandler get() {
		if(instance == null) {
			instance = new ErrorHandler();
		}
		return instance;
	}

	/**
	 * Sets up error screen
	 * @param msg What to display
	 * @param d Where to return
	 */
	public void displayError(String msg, Displayable d) {
		ErrorScreen screen = new ErrorScreen(root, "Error!", msg);
		screen.addCommand(Commander.ERROR_BACK);
		screen.addCommand(Commander.EXIT);
		screen.setHistoryScreen(d);
		root.getDisplay().setCurrent(screen);
		System.out.println("error");
	}
}
